<template>
  <div>
    <el-collapse-item :title="$t('基础配置')" name="1">
      <div style="padding: 10px 0" v-if="config.list">
        <div
          class="learun-row-form-input"
          :key="item.id"
          v-for="(item, index) in config.list"
        >
          <el-form-item :label="$t('图片上传')" style="margin-bottom: 8px">
            <l-upload
              v-model="item.imgurl"
              listType="picture-card"
              :chunkedUpload="lr_chunkedUpload"
              :getFileList="lr_getFileList"
              :deleteFile="lr_deleteFile"
            >
            </l-upload>
          </el-form-item>
          <el-form-item :label="$t('跳转功能')" style="margin-bottom: 0">
            <l-tree-select :options="appTree" v-model="item.moduleId">
            </l-tree-select>
          </el-form-item>
          <el-button
            :title="$t('删除')"
            v-if="config.list.length > 1"
            @click="handleRemoveCol(index)"
            class="learun-row-form-input-delete"
            circle
            plain
            size="mini"
            type="danger"
          >
            <i class="el-icon-close"></i>
          </el-button>
        </div>
      </div>
      <div style="margin-bottom: 10px">
        <el-button type="primary" size="mini" @click="handleAddCol"
          >{{ $t('添加') }}</el-button
        >
      </div>
    </el-collapse-item>
  </div>
</template>
<script>
export default {
  props: ["data"],
  inject: ["appDesign"],
  computed: {
    config() {
      return this.data;
    },
    appTree() {
      return this.appDesign.appTree || [];
    },
  },
  created() {
    /*if(this.config.dataCode){
            this.lr_loadDataSourceColNames(this.config.dataCode)
        }*/
  },
  methods: {
    init() {},
    myColNameList(dataCode) {
      if (this.lr_dataSourceCol && dataCode) {
        const colNameList = this.lr_dataSourceCol[dataCode] || [];
        return colNameList.map((t) => {
          return { value: t, label: t };
        });
      } else {
        return [];
      }
    },
    handleDataSourceChange(item) {
      const code = item.dataCode;
      if (!this.$validatenull(code)) {
        this.lr_loadDataSourceData(code);
        this.lr_loadDataSourceColNames(code);
      }

      item.dataValueKey = "";
    },
    handleAddCol() {
      this.config.list.push({
        id: this.$uuid(),
        moduleId: "",
        imgurl: "",
      });
    },
    handleRemoveCol(index) {
      if (this.config.list.length == 1) {
        this.$message({
          type: "warning",
          message: this.$t("必须保留一项"),
        });
      } else {
        this.config.list.splice(index, 1);
      }
    },
  },
};
</script>

